package com.example.administrator.waitan.homepage.recommend;

import android.os.Bundle;
import android.util.Log;
import android.widget.ListView;

import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.StringRequest;
import com.example.administrator.waitan.R;
import com.example.administrator.waitan.base.BaseActivity;
import com.example.administrator.waitan.tools.GsonRequest;
import com.example.administrator.waitan.tools.VolleySingleton;
import com.google.gson.Gson;

import java.util.List;

/**
 * Created by Administrator on 2016/1/25.
 */
public class RecommendActivity extends BaseActivity{
    private ListView mListView;
    private RecommendBaseAdapter mAdapter;
    private String url = "http://u1.tiyufeng.com/v2/section/content_list?portalId=15&start=0&id=351&limit=18&clientToken=fcc52145037d1097bf4c620af348ff1e";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_recommend);
        mListView = (ListView) findViewById(R.id.lv_recommend);
        mAdapter = new RecommendBaseAdapter(this);
        GsonRequest<RecommendBeans> beansGsonRequest = new GsonRequest<RecommendBeans>(url, RecommendBeans.class, new Response.Listener<RecommendBeans>() {
            @Override
            public void onResponse(RecommendBeans response) {

                mAdapter.addData(response.getResults());
                mListView.setAdapter(mAdapter);
            }
        }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {

            }
        });
//        StringRequest request = new StringRequest(url, new Response.Listener<String>() {
//            @Override
//            public void onResponse(String response) {
//                Gson gson  = new Gson();
//                RecommendBeans recommendBeans = gson.fromJson(response,RecommendBeans.class);
//                Log.i("asdad651",recommendBeans.getResults().toString());
//                List<RecommendInfo> recommendInfo = recommendBeans.getResults();
//                mAdapter.addData(recommendInfo);
//                mListView.setAdapter(mAdapter);
//            }
//        }, new Response.ErrorListener() {
//            @Override
//            public void onErrorResponse(VolleyError error) {
//
//            }
//        });
        VolleySingleton.getInstance()._addRequest(beansGsonRequest);
    }
}
